package com.ynet.middleground.user.model;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ynet.middleground.user.dao.ColdchainHistoryMapper;
import com.ynet.middleground.user.entity.ColdchainHistory;

import java.util.List;

import org.springframework.stereotype.Component;

/**
 * <p>
 * 冷链信息表历史表 服务实现类
 * </p>
 *
 * @author songyifan
 * @since 2020-08-03
 */

@Component
public class ColdChainHistoryModel extends ServiceImpl<ColdchainHistoryMapper, ColdchainHistory> {

	/**
     * 根据用户id删除相关冷链信息
     * 
     * @param userId
     */
    public void delete(Integer userId) {
        // 查询冷链信息，并批量删除
        LambdaQueryWrapper<ColdchainHistory> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(ColdchainHistory::getUserId, userId);
        this.remove(queryWrapper);
    }
    
    /**
     * 根据用户id查询相关冷链信息
     * 
     * @param userId
     */
    public List<ColdchainHistory> searchByUserId(Integer userId) {
        LambdaQueryWrapper<ColdchainHistory> queryWrapper = new LambdaQueryWrapper<ColdchainHistory>();
        queryWrapper.eq(ColdchainHistory::getUserId, userId);
        return this.list(queryWrapper);
    }
}
